﻿using System;
using Microsoft.Practices.Unity;
using UnityDemo.Models;

namespace UnityDemo.InjectionCode
{
    //http://stackoverflow.com/questions/2813322/unity-2-0-how-to-use-resolve-with-resolveroverride
    public class DependencyAttributeDemo : BaseFeatureDemo
    {
        // ResolverOverride lets you pass parameters to constructor at the time of resolving the class.
        public DependencyAttributeDemo()
        {
            var container = new UnityContainer();

            var consumer1 = container.Resolve<ServiceConsumer>(
                new PropertyOverride("Service", new ConcreteService(1)),
                new PropertyOverride("Service1", new ConcreteService(-1)));

            var consumer2 = container.Resolve<ServiceConsumer>(
                new PropertyOverride("Service", new ConcreteService(42)),
                new PropertyOverride("Service1", new ConcreteService(-42)));

            Console.WriteLine(consumer1.Service.Val);
            Console.WriteLine(consumer1.Service1.Val);

            Console.WriteLine(consumer2.Service.Val);
            Console.WriteLine(consumer2.Service1.Val);

            Console.ReadLine();
        }

        protected override void RegisterSamples()
        {
            // throw new NotImplementedException();
        }
    }
}